using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace PreguntaAlExperto.TransporterObjectsFramework
{
    public class SearchCriteria
    {
        private Dictionary<string, object> _parameterBag;
        private List<string> _parameterNames;
        private int _page;
        private int _pageSize;
        private string _order;
        private string _orderField = string.Empty;
        private string _columnFilter = string.Empty;
        private string _filterValue = string.Empty;

        /// <summary>
        /// Order to returns the data [ASC|DESC]
        /// </summary>
        public string Order
        {
            get { return _order; }
            set {
                switch (value)
                { 
                    case "Ascending":
                        _order = "Asc";
                        break;
                    case "Descending":
                        _order = "Desc";
                        break;
                    default:
                        _order = "";
                        break;
                }
                }
        }

        /// <summary>
        /// Field to order for
        /// </summary>
        public string OrderField
        {
            get { return _orderField; }
            set { _orderField = value; }
        }

        public SearchCriteria()
        {
            _parameterBag = new Dictionary<string, object>();
            _parameterNames = new List<string>();
            _page = 0;
            _pageSize = 0;
        }

        /// <summary>
        /// Page to return
        /// </summary>
        public int ActualPage
        {
            get { return _page; }
            set { _page = value; }
        }

        /// <summary>
        /// Records by page
        /// </summary>
        public int PageSize
        {
            get { return _pageSize; }
            set { _pageSize = value; }
        }

        /// <summary>
        /// Adds a new parameter
        /// </summary>
        /// <param name="ParameterName">Parameter Name</param>
        /// <param name="ParameterValue">Parameter Value. Value and Type is need it</param>
        public void addParameter(string ParameterName, object ParameterValue)
        {
            _parameterNames.Add(ParameterName);
            _parameterBag.Add(ParameterName, ParameterValue);
        }

        /// <summary>
        /// Returns a parameter based on his name
        /// </summary>
        /// <param name="ParameterName">Parameter Name</param>
        /// <returns></returns>
        public object getParameter(string ParameterName)
        { 
            object _returnObject;

            if (_parameterBag.TryGetValue(ParameterName, out _returnObject))
            {
                return _returnObject;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// Returns the list of parameters
        /// </summary>
        /// <returns></returns>
        public List<string> getParameterNameCollection()
        {
            return _parameterNames;
        }

        public void clearParameters()
        {
            this._parameterBag.Clear();
            this._parameterNames.Clear();
        }

        public string ColumnFiler
        {
            get { return _columnFilter; }
            set { _columnFilter = value; }
        }

        public string FilterValue
        {
            get { return _filterValue; }
            set { _filterValue = value; }
        }

    }
}
